<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-input v-model="query.value" clearable placeholder="输入关键字搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
    <el-select v-model="query.type" clearable placeholder="查找类型" class="filter-item" style="width: 130px">
      <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
    </el-select>
    <el-date-picker
      v-model="query.createTime"
      :picker-options="pickerOptions"
      class="filter-item"
      size="mini"
      type="datetimerange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      align="right"
    />
    <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <!-- 新增 -->
  </div>
</template>

<script>
// 查询条件
export default {
  props: {
    query: {
      type: Object,
      required: true
    },
    // eslint-disable-next-line vue/prop-name-casing
    sup_this: {
      type: Object,
      required: true
    },
    dictobj: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      createTime: '',
      queryTypeOptions: [
        { key: 'name', display_name: '文件名称' },
        { key: 'bucket', display_name: 'bucket' }
      ]
    }
  },
  methods: {
    // 去查询
    toQuery() {
      this.sup_this.page = 1
      this.sup_this.init()
    }

  }
}
</script>
